<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Layui</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link rel="stylesheet" href="../../../js/layui/css/layui.css" media="all">
    </head>
    <body>
        <form class="layui-form" id="addForm" action="">
            <div class="layui-form-item">
                <div class="layui-inline" style="display: none">
                    <label class="layui-form-label">ID：</label>
                    <div class="layui-input-inline">
                        <input type="tel" id="id" name="phone" lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">角色名称：</label>
                    <div class="layui-input-inline">
                        <input type="tel" id="name" name="phone" lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">顺序：</label>
                    <div class="layui-input-inline">
                        <input type="text" id="sort" name="email" lay-verify="number" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">描述：</label>
                    <div class="layui-input-inline">
                        <input type="text" id="description" name="email" lay-verify="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
        </form>

    <script src="../../../js/layui/layui.js"></script>
    <script src="../../../js/myJQ.js"></script>
    <script>
        layui.use(['table','jquery','layer'], function() {
            var basePath = getRootPath();
            var table = layui.table;
            var $ = layui.$;

            var form = layui.form;
            var layer = layui.layer;
            $(function () {
                debugger;
                var para= RequestParameter();
                if(!$.isEmptyObject(para)){
                    getRoleById(para.id);
                }
            });

            function getRoleById (id) {
                var param = {};
                param.id=id;
                $.ajax({
                    url:basePath+"/role/getRoleById",
                    dataType:"json",
                    async:false,
                    type:"POST",
                    data:param,
                    success:function (result) {
                        $("#id").val(result.data[0].id);
                        $("#name").val(result.data[0].name);
                        $("#sort").val(result.data[0].sort);
                        $("#description").val(result.data[0].description);
                    }
                });
            }

            /**
             * 如果是编辑，获取该数据的ID
             * @returns {Object}
             * @constructor
             */
            function RequestParameter(){
                var url = window.location.search; //获取url中"?"符后的字串
                var theRequest = new Object();
                if (url.indexOf("?") != -1) {
                    var str = url.substr(1);
                    var strs = str.split("&");
                    for(var i = 0; i < strs.length; i ++) {
                        theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]);
                    }
                }
                return theRequest
            }
        });
    </script>
    </body>
</html>